import React from 'react';
import {PixelRatio, Dimensions, StyleSheet} from 'react-native';
const dp2px = (dp) => PixelRatio.getPixelSizeForLayoutSize(dp);
const px2dp = (px) => PixelRatio.roundToNearestPixel(px);
let designSize = {width: 720, height: 1280}; //假设设计尺寸为：720*1280
let pxRatio = PixelRatio.get();
let win_width = Dimensions.get('window').width;
let win_height = Dimensions.get('window').height;
let width = dp2px(win_width);
let height = dp2px(win_height);
let design_scale = designSize.width / width;
height = height * design_scale;
let scale = 1 / pxRatio / design_scale;

const stylesContainer = StyleSheet.create({
  container: {
    width: width,
    height: height,
    transform: [
      {translateX: -width * 0.5},
      {translateY: -height * 0.5},
      {scale: scale},
      {translateX: width * 0.5},
      {translateY: height * 0.5},
    ],
  },
});

export default {stylesContainer, dp2px, px2dp, scale};
